﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.SysBasic
{
    public partial class OUserAdd :PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[]{Permission.新增};
            }
        }

        protected override string DWZRef
        {
            get { return "OUserList"; }
        }
        #region
        protected string GetRoleList()
        {
            string perhtml = "";
            string peritemtemp = "<option value=\"{0}\" >{1}</option>";
            DataTable alltop = ORoleController.GetAll();
            // string item;
            perhtml = "";
            foreach (DataRow item in alltop.Rows)
            {
                perhtml = perhtml + string.Format(peritemtemp, item["RoleId"], item["RoleName"]);
            }
            return perhtml;
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "adduser")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {
            OUserInfo obj = Request.SerializableObject<OUserInfo>();
            obj.State = 1;
            obj.PartsEmail = "";
            obj.SrvActUserId = 0;
            obj.UserType = 1;
            if (OUserController.CheckUserName(obj.UserName))
            {
                AlertJson("登陆帐户名已存在,请重新输入.");
                return;
            }


            if (OUserController.Add(obj))
                SuccessJson("添加成功");
            else
                ErrorJson("添加失败");
        }
    }
}